<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-5-31
 * Time: 下午3:11
 */
class Minterviewvote extends CI_MODEL
{
    function __construct()
    {
        parent::__construct();
    }

    /**
     * 检测是否已投过票
     * @param $uid
     * @param $voteUid
     * @param $interviewId
     * @return bool
     */
    function checkVote($uid,$voteUid,$interviewId)
    {
        $sql = "select * from `tbinterview_vote` where `uid` = ? and `vote_uid`=? and `interview_id`=?";
        $query = $this->db->query($sql,array($uid,$voteUid,$interviewId));
        $exists = false;
        if($query->num_rows() > 0){
            $exists = true;
        }
        return $exists;
    }

    /**
     * 写入投票记录
     * @param $uid
     * @param $voteUid 投票人uid
     * @param $interviewId
     * @return mixed
     */
    function insertVote($uid,$voteUid,$interviewId)
    {
        $data = array(
            'uid' => $uid,
            'interview_id' => $interviewId,
            'vote_uid' => $voteUid
        );

        $this->db->insert('tbinterview_vote', $data);
        return $this->db->insert_id();

    }

}